// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MainPanel.java

package com.boci.clientapp.main;

import com.boci.clientapp.authentication.LoginPanel;
import com.boci.clientapp.balance.BalanceTabSclPane;
import com.boci.clientapp.history.HistoryTabSclPane;
import com.boci.clientapp.holding.HoldingTabSclPane;
import com.boci.clientapp.main.constant.MainPanelConst;
import com.boci.clientapp.orderstatus.OrderStatusTabSclPane;
import com.boci.clientapp.questions.QuestionsTabSclPane;
import com.boci.clientapp.staffoption.StaffOptionTabSclPane;
import com.boci.clientapp.trading.TradingScrPanel;
import com.boci.clientapp.trading.TradingTabSclPane;
import com.boci.clientapp.trading.vo.TradingVO;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.ui.AbstractTabSclPane;
import com.boci.common.ui.control.ToolPanel;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.PerformanceLogger;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

// Referenced classes of package com.boci.clientapp.main:
//            ApplicationService, ClientAppLoader

public class MainPanel extends JPanel
    implements ChangeListener
{

    public LoginPanel getLoginPanel()
    {
        return loginPanel;
    }

    public AbstractPanel getPanel(String pStrModule, String pStrScreen)
    {
        AbstractTabSclPane tabSclPane = (AbstractTabSclPane)tabMap.get(pStrModule);
        return tabSclPane.getPanel(pStrScreen);
    }

    public AbstractTabSclPane getTab(String pStrModule)
    {
        AbstractTabSclPane tabSclPane = (AbstractTabSclPane)tabMap.get(pStrModule);
        return tabSclPane;
    }

    private void initConfig()
    {
    }

    public void setAccNoList(String pStrAccNo[], String pPriAccNo)
    {
        toolPanel.setAccountNoList(pStrAccNo, pPriAccNo);
    }

    public MainPanel(boolean pStandaloneFlag, Locale pLocale)
    {
        tabMap = new HashMap();
        tabResKeyMap = new HashMap();
        initConfig();
        initGUI(pStandaloneFlag, pLocale);
        setText(pLocale);
        showLoginPanel(true);
    }

    public void setText(Locale pLocale)
    {
        toolPanel.setText(pLocale);
        loginPanel.setText(pLocale);
        Set keySet = tabMap.keySet();
        Iterator iterator = keySet.iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Object obj = tabMap.get(iterator.next());
            if(obj instanceof AbstractTabSclPane)
            {
                AbstractTabSclPane tabSclPane = (AbstractTabSclPane)obj;
                tabSclPane.setText(pLocale);
            }
        } while(true);
        setFont(pLocale);
        MessagesConfigurator msgConf = ClientAppLoader.getMessagesConfigurator();
        for(int i = 0; i < centerTabPane.getTabCount(); i++)
        {
            Object objTitleKey = tabResKeyMap.get(new Integer(i));
            if(objTitleKey != null && (objTitleKey instanceof String))
            {
                String strTitle = msgConf.getUIMessages((String)objTitleKey, pLocale);
                centerTabPane.setTitleAt(i, strTitle);
                centerTabPane.setToolTipTextAt(i, strTitle);
            }
        }

    }

    private void setFont(Locale pLocale)
    {
        centerTabPane.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
    }

    private void initGUI(boolean pStandaloneFlag, Locale pLocale)
    {
        initOperationPanel(pStandaloneFlag, pLocale);
        loginPanel = new LoginPanel(pLocale);
        setLayout(new BoxLayout(this, 0));
        add(loginPanel);
        add(operationPanel);
    }

    private void setTabColor()
    {
        for(int i = 0; i < centerTabPane.getTabCount(); i++)
            centerTabPane.setForegroundAt(i, Color.LIGHT_GRAY);

        centerTabPane.setForegroundAt(centerTabPane.getSelectedIndex(), Color.WHITE);
    }

    public void showScreen(String pModName, String pScrName)
    {
        showScreen(pModName, pScrName, true);
    }

    public void showScreen(String pModName, String pScrName, boolean pRefreshPanel)
    {
        centerTabPane.removeChangeListener(this);
        AbstractTabSclPane tabSclPane = (AbstractTabSclPane)tabMap.get(pModName);
        centerTabPane.setSelectedComponent(tabSclPane);
        tabSclPane.showScreen(pScrName, pRefreshPanel);
        setTabColor();
        centerTabPane.addChangeListener(this);
    }

    public void showScreen(String pModName)
    {
        centerTabPane.removeChangeListener(this);
        AbstractTabSclPane tabSclPane = (AbstractTabSclPane)tabMap.get(pModName);
        centerTabPane.setSelectedComponent(tabSclPane);
        tabSclPane.showDefaultScr();
        setTabColor();
        centerTabPane.addChangeListener(this);
    }

    public String getSelectedModuleName()
    {
        String strModuleName = null;
        Object obj = centerTabPane.getSelectedComponent();
        if(obj instanceof AbstractTabSclPane)
        {
            AbstractTabSclPane tabSclPane = (AbstractTabSclPane)obj;
            strModuleName = tabSclPane.getModuleName();
        }
        return strModuleName;
    }

    public void showLoginPanel(boolean pShowLogin)
    {
        if(pShowLogin)
        {
            loginPanel.setVisible(true);
            operationPanel.setVisible(false);
            loginPanel.refresh();
        } else
        {
            loginPanel.setVisible(false);
            operationPanel.setVisible(true);
            showScreen("TRADING_MODULE", "TRADING_SCREEN");
            TradingScrPanel tradingScrPanel = (TradingScrPanel)getPanel("TRADING_MODULE", "TRADING_SCREEN");
            tradingScrPanel.chgMarket("HK_MARKET");
            toolPanel.reset();
        }
    }

    public void showTradingPanel(String pMarket, String pCode, String pPrice, String pTransType)
    {
        ApplicationService appServ = ApplicationService.getInstance();
        String strModName = "TRADING_MODULE";
        String strTrdScrName = "TRADING_SCREEN";
        TradingScrPanel tradingScrPanel = (TradingScrPanel)(TradingScrPanel)appServ.getMainPanel().getPanel(strModName, strTrdScrName);
        TradingVO tradingVO = new TradingVO("", "");
        tradingVO.setSymbol(pCode);
        tradingVO.setPrice(pPrice);
        if(pTransType.equals("BUY"))
            tradingVO.setBuyOrSell("BUY");
        else
        if(pTransType.equals("SELL"))
            tradingVO.setBuyOrSell("SELL");
        if(pMarket.equals("US"))
        {
            appServ.getMainPanel().showScreen(strModName, strTrdScrName);
            tradingScrPanel.chgMarket("US_MARKET");
            tradingScrPanel.refresh(tradingVO);
        } else
        {
            appServ.getMainPanel().showScreen(strModName, strTrdScrName);
            tradingScrPanel.chgMarket("HK_MARKET");
            tradingScrPanel.refresh(tradingVO);
        }
        toolPanel.enableAcctNO(true);
    }

    private void initOperationPanel(boolean pStandaloneFlag, Locale pLocale)
    {
        operationPanel = new JPanel();
        operationPanel.setLayout(new BorderLayout());
        toolPanel = new ToolPanel(pStandaloneFlag, pLocale);
        operationPanel.add(toolPanel, "North");
        initTab(pLocale);
    }

    private void initTab(Locale pLocale)
    {
        centerTabPane = new JTabbedPane();
        operationPanel.add(centerTabPane);
        centerTabPane.setUI(new BasicTabbedPaneUI());
        centerTabPane.setOpaque(false);
        centerTabPane.setBackground(new Color(162, 0, 50));
        centerTabPane.setForeground(Color.LIGHT_GRAY);
        addTab(new TradingTabSclPane(pLocale), MainPanelConst.TAB_IDX_TRADING, "MAIN.TRADING_TAB_HEADER");
        addTab(new OrderStatusTabSclPane(pLocale), MainPanelConst.TAB_IDX_ORDERSTATUS, "MAIN.ORDERSTATUS_TAB_HEADER");
        addTab(new HistoryTabSclPane(pLocale), MainPanelConst.TAB_IDX_HISTORY, "MAIN.HISTORY_TAB_HEADER");
        addTab(new HoldingTabSclPane(pLocale), MainPanelConst.TAB_IDX_HOLDING, "MAIN.HOLDING_TAB_HEADER");
        addTab(new BalanceTabSclPane(pLocale), MainPanelConst.TAB_IDX_ACC_BALANCE, "MAIN.ACC_BALANCE_TAB_HEADER");
        addTab(new StaffOptionTabSclPane(pLocale), MainPanelConst.TAB_IDX_STAFF_OPT, "MAIN.STAFF_OPT_TAB_HEADER");
        addTab(new QuestionsTabSclPane(pLocale), MainPanelConst.TAB_IDX_COM_QUESTION, "MAIN.COM_QUESTION_TAB_HEADER");
        setTabColor();
        centerTabPane.addChangeListener(this);
    }

    private void addTab(AbstractTabSclPane pTabSclPane, Integer pSequence, String pTabResKey)
    {
        String strModuleName = pTabSclPane.getModuleName();
        javax.swing.Icon lineIcon = ClientAppLoader.getTabIcon();
        centerTabPane.addTab("", lineIcon, pTabSclPane);
        centerTabPane.addTab("", pTabSclPane);
        tabMap.put(strModuleName, pTabSclPane);
        tabResKeyMap.put(pSequence, pTabResKey);
    }

    public void stateChanged(ChangeEvent e)
    {
        PerformanceLogger.startAppTimer();
        toolPanel.enableAcctNO(true);
        setTabColor();
        Object obj = centerTabPane.getSelectedComponent();
        String strModuleName = "";
        if(obj instanceof AbstractTabSclPane)
        {
            AbstractTabSclPane tabSclPane = (AbstractTabSclPane)obj;
            tabSclPane.showDefaultScr();
            strModuleName = tabSclPane.getModuleName();
        }
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append("MAIN_SCREEN.CHANGE_TAB(").append(strModuleName).append(")").toString());
    }

    public void refreshScreen()
    {
        Object obj = centerTabPane.getSelectedComponent();
        if(obj instanceof AbstractTabSclPane)
        {
            AbstractTabSclPane tabSclPane = (AbstractTabSclPane)obj;
            tabSclPane.refreshScreen();
        }
    }

    public void enableAcctNo(boolean enabled)
    {
        toolPanel.enableAcctNO(enabled);
    }

    private LoginPanel loginPanel;
    private JPanel operationPanel;
    private JTabbedPane centerTabPane;
    private ToolPanel toolPanel;
    private HashMap tabMap;
    private HashMap tabResKeyMap;
}
